package com.example.demo.mapper;

import com.example.demo.enumeration.Campus;
import com.example.demo.pojo.entity.User;
import com.example.demo.pojo.vo.UserDetailVO;
import com.example.demo.pojo.vo.UserProfileVO;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    @Select("select * from user where id = #{id}")
    User selectById(Long id);

    @Select("select name from user where id = #{id}")
    String selectNameById(Long id);

    @Select("select * from user where phone = #{phone}")
    User selectByPhone(String phone);

    @Select("select * from user where name = #{name}")
    User selectByName(String name);

    @Insert("insert into user (phone, name, password, student_id, campus, picture, create_time, update_time) values (#{phone}, #{name}, #{password}, #{studentId}, #{campus}, #{picture}, now(), now())")
    boolean createUser(String phone, String name, String password, String studentId, Campus campus, String picture);

    @Select("select id, name, picture from user where id = #{id}")
    UserProfileVO getUserProfile(Long id);

    @Select("select id, name, campus, picture, credit, create_time, update_time from user where id = #{id}")
    UserDetailVO getUserDetail(Long id);

    @Update("update user set name = #{name}, campus = #{campus}, update_time = now() where id = #{id}")
    boolean updateInfo(String name, Campus campus, Long id);

    @Update("update user set picture= #{url}, update_time = now() where id = #{id}")
    boolean updatePicture(String url, Long id);

    @Update("update user set password= #{password}, update_time = now() where id = #{id}")
    boolean updatePassword(String password, Long id);
}
